package com.dqhl.smartstable.activity;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.smartstable.R;
import com.dqhl.smartstable.base.BaseActivity;
import com.dqhl.smartstable.util.DeviceUtils;

import java.io.IOException;


/**
 * Created by mac on 16/10/14.
 * 设置
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener {

    private ImageView iv_top_back;
    private TextView tv_top_center;

    private TextView tv_version;
    private Button btn_logout;
//    private Button btn_ring;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        initView();
    }

    private void initView() {
        iv_top_back = (ImageView) findViewById(R.id.iv_top_back);
        tv_top_center = (TextView) findViewById(R.id.tv_top_center);
        tv_top_center.setText("设 置");

        tv_version = (TextView) findViewById(R.id.tv_version);
        btn_logout = (Button) findViewById(R.id.btn_logout);
//        btn_ring = (Button) findViewById(R.id.btn_ring);
        String strVersion = "当前版本: v" + DeviceUtils.getVersion(this);
        tv_version.setText(strVersion);

        iv_top_back.setOnClickListener(this);
        btn_logout.setOnClickListener(this);
//        btn_ring.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.btn_logout:
                doLogout();
                break;
//            case R.id.btn_ring:
//                doRing();
//                break;
        }
    }

    /**
     * 退出登录
     */
    private void doLogout() {
        sp.edit().clear().apply();
        app.exit();
    }

//    private void doRing(){
//        Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
//		MediaPlayer player = new MediaPlayer();
//        try {
//            player.setDataSource(getApplicationContext(), alert);
//            final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//            if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) {
//                player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
//                player.setLooping(true);
//                player.prepare();
//                player.start();
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
}
